package com.huluobo.a2206parkdemo

import androidx.lifecycle.MutableLiveData
import com.huluobo.base.bean.UserBean
import com.huluobo.base.db.UserDao
import com.huluobo.base.mvvm.BaseViewModel
import com.huluobo.base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import okhttp3.RequestBody
import javax.inject.Inject

/**
 *  Created by LC on 2024/10/19.
 */
@HiltViewModel
class MainViewModel @Inject constructor(
    val apiService: ApiService,
    val dao: UserDao
) : BaseViewModel() {
    val getNewsSuccess by lazy { MutableLiveData<String>() }
    fun getAllNews(body: RequestBody) {
        executeNetwork(
            { apiService.getNews(body) },
            getNewsSuccess::postValue
        )
    }

    val queryUserInfoSuccess by lazy { MutableLiveData<UserBean>() }
    fun queryUserInfo(username: String) {
        executeDb(
            {
                dao.queryUserInfoByName(username)
            },
            queryUserInfoSuccess::postValue
        )
    }
}